from TDhelper.db.mysql.base import db_pool
from src.settings import DATABASES

config = {
    "host": DATABASES['default']['HOST'],
    "port": DATABASES['default']['PORT'],
    "user": DATABASES['default']['USER'],
    "password": DATABASES['default']['PASSWORD'],
    "database": DATABASES['default']['NAME']
}

db_helper = db_pool(config, 1)

def select(sql):
    try:
        session= db_helper.getSession()
        if session:
            try:
                cursor= session.cursor()
                if cursor:
                    cursor.execute(sql)
                    data= cursor.fetchall()
                    return data
                return None
            finally:
                cursor.close()
                session.close()
        return None
    except Exception as e:
        return None